package com.tfswx.jkgl.designer.datasource;

import cn.hutool.extra.spring.SpringUtil;
import com.tfswx.jkgl.designer.dto.xmgl.XmxxQueryInputDTO;
import com.tfswx.jkgl.designer.dto.xmgl.XmxxQueryOutputDTO;
import com.tfswx.jkgl.designer.service.XmglService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @author ricky
 * @date 2021/12/25
 */
@Slf4j
@Configuration
public class InitDatabase {

    private static XmglService xmglService;
    private static DataSourceConfiguration dataSourceConfiguration;

    @PostConstruct
    void init() {
        xmglService = SpringUtil.getBean(XmglService.class);
        dataSourceConfiguration = SpringUtil.getBean(DataSourceConfiguration.class);
        regist();
    }

    public static void regist() {
        log.info("注册数据源");
        XmxxQueryInputDTO xmxxQueryInputDTO = new XmxxQueryInputDTO();
        List<XmxxQueryOutputDTO> xmxxQueryOutputDTOS = xmglService.queryXmxx(xmxxQueryInputDTO);
        dataSourceConfiguration.regist(xmxxQueryOutputDTOS);
    }
}
